import Vue from "vue"
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/home.vue'
import Welcome from '../components/welcome.vue'
import Users from '../components/user/Users.vue'
Vue.use((VueRouter))
//  route 配置
const routes = [
	{
	path:'/',
	redirect:'/login'
	},
  {
    path: '/login',  // url 匹配地址
    component: Login // 渲染的组价
  },
  {
	path:'/home',
	component:Home,
	redirect:'/welcome',
	children:[
		{
			path:'/welcome',
			component:Welcome,
		},
		{
			path:'/users',
			component:Users,
		}
	]
  },


];

//路由导航


// 创建router实例
const router = new VueRouter({
  routes,
   mode: 'history',
 
});
//路由导航守卫
router.beforeEach((to,from,next)=>{
	if(to.path==='/login') return next();
	 const tokenstr=window.sessionStorage.getItem("token");
	 if(!tokenstr) return   next("/login")
	 next();
})
// 导出router
export default router;